home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-13 | 19.5 KB | 964 lines | [TEXT/MPS ] |
- %
- % LMforeigns.p: Foreign and Builtin routines for the Logic Manager
- %
- % Copyright (c) 1988, 1989, 1990 by Apple Computer, Inc.
- % Logic Manager 1.0d2
- % Ruben Kleiman (Apple Computer, Inc; Advanced Technology Group)
- % Thanks to Michael Poe, Steve Weyer, Larry Tesler, not least
- % to Andy Turk and unsung others.
-
- % This code is the property of Apple Computer, Inc. and is considered
- % company confidential. Use of it is at the user's own risk. Apple
- % Computer, Inc. shall not be liable for any direct or indirect
- % physical or emotional harm or loses resulting from the use of
- % the Logic Manager.
- %
-
-
- %
- % +Arg is an input argument
- % -Arg is an output argument
- % ?Arg is not necessarily input or output, usage varies
- %
-
- %
- %% cut
- %
- % Removes any choicepoints created since the parent procedure call.
- %
-
- rule( cut, cut ).
-
- %
- %% abolish( +Name, +Arity )
- %
- % Removes all clauses for the procedure Name/Arity from the database.
- %
-
- %
- %% write( +Term )
- %
- % Writes a printed representation of Term to the standard output.
- %
-
- %
- %% nl
- %
- % Prints a new-line character to standard output.
- %
-
- %
- %% call( +Goal )
- %
- % Succeeds when Goal is provable.
- %
-
- %
- %% asserta( +Clause )
- %
- % Adds the Clause to the beginning of the specified procedure
- % in the database.
- %
-
- %
- %% assertz( +Clause )
- %
- % Adds the Clause to the end of the specified procedure
- % in the database.
- %
-
- %
- %% mangle( +ArgN, +Structure, +Argument )
- %
- % The ArgNth argument of the compound term, Structure, is destructively
- % modified to be Argument. This modification SURVIVES failure.
- %
-
- %
- %% =( ?X, ?Y )
- %
- % Unifies X and Y.
- %
-
- =(X,X).
-
- %
- %% read( ?Term )
- %
- % Pauses to allow the user to type in a term to standard input. This
- % term is then unified with Term.
- %
-
- %
- %% lockedproc( +Name, +Arity )
- %
- % Succeeds when the procedure, Name/Arity, has been locked.
- %
-
- %
- %% lockproc( +Name, +Arity )
- %
- % Locks the procedure, Name/Arity. This means that abolish/2,
- % clause/2, retract/1, asserta/1, and assertz/2 will never modify
- % or examine Name/Arity.
- %
-
- %
- %% compare( -Relation, +LeftArg, +RightArg )
- %
- % Relation will be bound to '>', '<' or '=' depending on whether:
- %
- % LeftArg < RightArg or
- % LeftArg = RightArg or
- % LeftArg > RightArg
- %
- %
- % variables < numbers < atoms < structured terms < buffers
- %
- % compare/3 defines the standard order.
- %
-
- rule( compare( Relation, Left, Right ),
- and( $compare( Left, Right ),
- getterm( Relation )
- )).
-
- %
- %% @<( +Left, +Right )
- %% @=<( +Left, +Right )
- %% @>=( +Left, +Right )
- %% @>( +Left, +Right )
- %% ==( +Left, +Right )
- %
- % These predicates use compare/3 to compare their arguments according
- % to the standard order.
- %
-
- rule( @<( Left, Right ),
- compare( <, Left, Right )).
-
- rule( @=<( Left, Right ),
- and( compare( <, Left, Right ),
- cut
- )).
- rule( @=<( Left, Right ),
- compare( =, Left, Right )).
-
- rule( @>( Left, Right ),
- compare( >, Left, Right )).
-
- rule( @>=( Left, Right ),
- and( compare( >, Left, Right ),
- cut
- )).
- rule( @>=( Left, Right ),
- compare( =, Left, Right )).
-
- rule(==( Left, Right ),
- compare( =, Left, Right )).
-
- %
- %% different( +X, +Y )
- %
- % Succeeds when X and Y are not ==/2.
- %
-
- rule(different(X,X),
- and(cut, fail) ).
- different(_,_).
-
- %
- %% typeof( Term, Type )
- %
- % Type is unified with an atom representing the type of Term
- %
- % variable
- % integer
- % integer32
- % atom
- % compound
- % float
- % string
- % buffer
- %
-
- rule( typeof( Term, Type ),
- and( $typeof( Term ),
- getterm( Type )
- )).
-
- %
- %% number( +Arg )
- %
- % Succeed when Arg is bound to an integer or a floating point.
- %
-
- rule( number( N ),
- and( typeof( N, Type ),
- and( numberType( Type ),
- cut
- ))).
-
- numberType( integer ).
- numberType( integer32 ).
- numberType( float ).
-
- %
- %% arg( +ArgN, +Structure, -Argument )
- %
- % Structure must be bound to a compound term. The Nth argument of this
- % term will be unified with Argument.
- %
-
- rule( arg( Item, Structure, Argument ),
- and( $arg( Item, Structure ),
- getterm( Argument )
- )).
-
- %
- % functor( -Structure, +Name, +Arity ) also functor( +Structure, -Name, -Arity )
- %
- % When Structure is an unbound variable, a new compound term with
- % a principal functor of Name/Arity will be unified with Structure. All
- % the arguments of the structure are fresh unbound variables.
- %
- % In the other mode, the second and third arguments will be unified with
- % the name and arity of the principal functor of Structure.
- %
-
- rule(functor(Structure,Functor,Arity),
- and(var(Structure),
- and(cut,
- and($build(Functor,Arity),getterm(Structure))))).
-
-
- rule(functor(Structure,Functor,Arity),
- and($name(Structure),
- and(getterm(Functor),
- and($arity(Structure),getterm(Arity) )))).
-
-
- rule(name(Structure,Name),
- and($name(Structure), getterm(Name) )).
- rule(arity(Structure,Arity),
- and($arity(Structure), getterm(Arity) )).
-
- %
- %% nonvar( +Term )
- %% var( +Term )
- %% atom( +Term )
- %% atomic( +Term )
- %% integer( +Term )
- %
- % These are used to identify the type of term passed.
- %
-
- rule( nonvar( Term ),
- and( typeof( Term, variable ),
- and( cut,
- fail
- ))).
- nonvar( Term ).
-
- rule( var( Term ),
- typeof( Term, variable )
- ).
- rule( atom( Term ),
- typeof( Term, atom )
- ).
-
- rule( buffer( Term ),
- typeof( Term, buffer )
- ).
-
- rule( float( Term ),
- typeof( Term, float )
- ).
-
- atomicType( integer ).
- atomicType( integer32 ).
- atomicType( atom ).
-
- rule( atomic( Term ),
- and( typeof( Term, Type ),
- and( atomicType( Type ),
- cut
- ))).
-
- integerType( integer ).
- integerType( integer32 ).
-
- rule( integer( Term ),
- and( typeof( Term, Type ),
- and( integerType( Type ),
- cut
- ))).
-
- rule( nonvar( Term ),
- and( var( Term ),
- and( cut,
- fail
- ))).
- nonvar( Term ).
-
-
- %
- %% is(-Result,+Expression)
- %
- % The result of the arithmetic evaluation of Expression is unified
- % with Result.
- %
-
- rule( is( Result, Expression ),
- % and( writel( Expression ),
- and( eval( Expression ),
- getterm( Result )
- )).
-
- %
- %% atomchars( +Atom, -Chars ) also atomchars( -Atom, +Chars )
- %
- % Translates an atom into a list of its ASCII characters and
- % vice versa.
- %
-
- rule(atomchars(Atom,ExplodedAtom),
- and(atomic(Atom),
- and(cut,
- and($atomchars(Atom),getterm(ExplodedAtom) )))).
-
-
- rule(atomchars(ImplodedAtom,Atom),
- and(var(ImplodedAtom),
- and($implode(Atom),getterm(ImplodedAtom) ))).
-
- %
- %% true
- %
- % Always succeeds.
- %
-
- true.
-
-
- %
- %% not( +Goal )
- %
- % Succeeds when Goal is not provable.
- %
-
-
- rule(not(Goal),
- and(call(Goal),
- and(cut,fail))).
-
- rule(not(Goal),true).
-
- %
- %% or( +Goal1, +Goal2 )
- %
- % Succeeds when either Goal1 or Goal2 is provable.
- %
-
- rule(or(Goal1,Goal2), call(Goal1)).
- rule(or(Goal1,Goal2), call(Goal2)).
-
- %
- %% and( +Goal, +Goal )
- %
- % Succeeds when both Goal1 and Goal2 are both provable (in order).
- %
-
- rule( and( Goal1, Goal2 ),
- % and( writel( and1( Goal1 )),
- and( call( Goal1 ),
- % and( writel( and2( Goal2 )),
- call( Goal2 )
- )).
-
- %
- %% length( +List, -Length )
- %
- % Length is unified with the length List.
- %
-
- rule( length( List, Len ),
- length2( List, 0, Len )).
-
- length2( nil, Len, Len ).
- rule( length2( cons( _, Tail ), SoFar, Total ),
- and( is( OneMore, add( SoFar, 1 )),
- length2( Tail, OneMore, Total )
- )).
-
- %
- %% sort( +List, -SortedList )
- %
- % List is sorted according to the standard order defined by compare/3.
- % Duplicate elements (==/2) of List are removed.
- %
-
-
- rule(sort(List,SortedList),
- and(length(List,Length),
- sort(Length,List,_,SortedList) )).
-
- rule(sort(2,cons(X1,L1),L,R),
- and(cut,
- and(comprises(L1,X2,L),
- and(compare(Delta,X1,X2),
- sort2(Delta,X1,X2,R) )))).
-
- sort2(<,X1,X2,cons(X1,cons(X2,nil))).
- sort2(>,X1,X2,cons(X2,cons(X1,nil))).
- sort2(=,X1,X2,cons(X2,nil)).
-
- rule(sort(1,cons(X,L),L,cons(X,nil)),
- cut).
-
- rule(sort(0,L,L,nil),cut).
- rule(sort(N,L1,L3,R),
- and(is(N1,idiv(N,2)),
- and(is(N2,sub(N,N1)),
- and(sort(N1,L1,L2,R1),
- and(sort(N2,L2,L3,R2),merge(R1,R2,R) ))))).
-
- rule(merge(nil,R,R),cut).
- rule(merge(R,nil,R),cut).
-
- rule(merge(R1,R2,cons(X,R)),
- and( comprises(R1,X1,R1a),
- and( comprises(R2,X2,R2a),
- and( compare(Delta,X1,X2),merge2(Delta,X,X1,X2,R1,R2,R1a,R2a,R) )))).
-
- rule(merge2(<,X,X,_,_,R2,R1a,_,R),
- and(cut,
- merge(R1a,R2,R))).
-
- rule(merge2(>,X,_,X,R1,_,_,R2a,R),
- and(cut,
- merge(R1,R2a,R) )).
-
- rule(merge2(=,X,X,_,_,_,R1a,R2a,R),
- merge(R1a,R2a,R) ).
-
-
- comprises(cons(X,L),X,L).
-
-
- % copy/2
- %
- % Duplicates a term on the heap.
- %
- % copy(+Original,-Duplicate)
-
- rule(copy(Original,Duplicate),
- and($copy(Original),getterm(Duplicate) )).
-
-
- %
- %% findall( +Template, +Goal, -Solutions )
- %
- % All the instances of Template when Goal is provable are
- % collected into the list Solutions. There is no quantification
- % and Solutions may contain duplicates.
- %
-
- rule(findall(Template,Call,Bag),
- and(=(WorkingBag,cons(nil,nil)),
- and(collect(Template,Call,WorkingBag), arg(1,WorkingBag,Bag) ))).
-
- rule(collect(Template,Call,Bag),
- and(call(Call),
- and(copy(Template,CopiedTemplate),
- and(addSolution(CopiedTemplate,Bag),fail )))).
-
- collect(_,_,_).
-
- rule(addSolution(Solution,Bag),
- and(=(Bag,cons(nil,nil)),
- and(cut,
- and(=(SingleSolution,cons(Solution,nil)),
- and(mangle(1,Bag,SingleSolution), mangle(2,Bag,SingleSolution) ))))).
-
- rule(addSolution(Solution,Bag),
- and(=(Bag,cons(_,BagEnd)),
- and(=(NewEnd,cons(Solution,nil)),
- and(mangle(2,Bag,NewEnd), mangle(2,BagEnd,NewEnd) )))).
-
-
- %
- % append( ?List1, ?List2, ?NewList )
- %
- % NewList is the result of appending List1 before List2.
- %
-
- append(nil,List2,List2).
- rule(append(cons(H,T),L,cons(H,R)), append(T,L,R) ).
-
-
- %
- % univ( +Term, -List ) also univ( -Term, +List )
- %
- % Term is a compound term, and List is a list whose
- % first element is the principal functor of Term, and whose other
- % elements are the arguments of Term in order.
- %
-
- rule( univ( Structure, cons( Functor, Args )),
- and( functor( Structure, Functor, Arity ),
- and( cut,
- univInstall( Structure, 1, Arity, Args )
- ))).
-
- rule( univ( Structure, cons( Functor, Args )),
- and( atom( Functor ),
- and( length( Args, Arity ),
- and( cut,
- and( functor( Structure, Functor, Arity ),
- univInstall( Structure, 1, Arity, Args )
- )))))).
-
- rule( univInstall( Struct, N, Arity, nil ),
- and( @>( N, Arity ),
- cut
- )).
- rule( univInstall( Struct, N, Arity, cons( Arg, Args )),
- and( arg( N, Struct, Arg ),
- and( is( N1, add( N, 1 )),
- univInstall( Struct, N1, Arity, Args )
- ))).
-
- %
- %% writel( +Term )
- %
- % writes Term to standard out followed by a new-line
- %
-
- rule( writel( Term ),
- and( write( Term ),
- nl
- )).
-
- rule( notlocked( Head ),
- and( functor( Head, Name, Arity ),
- and( lockedproc( Name, Arity ),
- and( cut,
- fail
- )))).
- notlocked( Head ).
-
- %
- %% getcount( ?Count )
- %
- % Unifies Count with the inference countdown value.
- %
-
- rule( getcount( X ),
- and( getcount,
- getterm( X )
- )).
-
- %
- %% clause( +Head, ?Body )
- %
- % Succeeds when there is a clause in the database whose head is
- % unifiable with Head and whose body is unifiable with Body.
- %
-
- rule( clause( Head, Body ),
- and( notlocked( Head ),
- and( =( DecompState, rule( Head, nil )),
- and( =( NormalState, nstate( Count, IState )),
- and( getcount( Count ),
- and( getistate( IState ),
- and( decompilationOn( DecompState, NormalState ),
- and( call( Head ),
- and( decompilationOff( DecompState, NormalState ),
- and( fixClause( DecompState ),
- arg( 2, DecompState, Body )
- )))))))))).
-
- rule( decompilationOn( DecompState, NormalState ),
- changeState( 2, DecompState )
- ).
- rule( decompilationOn( DecompState, NormalState ),
- turnOffDecompiler( NormalState )
- ).
-
- rule( decompilationOff( DecompState, nstate( Count, IState )),
- changeState( Count, IState )
- ).
- rule( decompilationOff( DecompState, NormalState ),
- and( mangle( 2, DecompState, nil ),
- and( changeState( 2, DecompState ),
- fail
- ))).
-
- rule( interrupt( decompilationOff( DState, NState )),
- and( nonvar( DState ),
- and( cut,
- decompilationOff( DState, NState )
- ))).
-
- rule( interrupt( turnOffDecompiler( nstate( Count, IState ))),
- and( cut,
- and( changeState( Count, IState ),
- fail
- ))).
-
- rule( interrupt( Goal ),
- and( getistate( depthLimit ),
- and( write( 'depth limit exceeded with ' ),
- and( writel( Goal ),
- halt
- )))).
-
- rule( interrupt( Goal ),
- and( getistate( DState ),
- and( =( New, and( Goal, nil )),
- and( mangle( 2, DState, New ),
- changeState( 1, New )
- )))).
-
- rule( getistate( X ),
- and( getistate,
- getterm( X ))).
-
- rule( changeState( Count, InterruptField ),
- and( setistate( InterruptField ),
- setcount( Count )
- )).
- rule( fixClause( Clause ),
- and( =( Clause, rule( _, nil )),
- and( cut,
- mangle( 2, Clause, true )
- ))).
- rule( fixClause( Body ),
- and( arg( 2, Body, and( G, nil )),
- and( cut,
- mangle( 2, Body, G )
- ))).
- rule( fixClause( Body ),
- and( arg( 2, Body, Tail ),
- fixClause( Tail )
- )).
-
- %
- %% retract( +Clause )
- %
- % Succeeds when Clause is a clause in the database. After retract/1 succeeds,
- % the clause is removed from the database.
- %
-
- rule( retract( rule( Head, Body )),
- and( cut,
- retract2( Head, Body )
- )).
- rule( retract( Head ),
- retract2( Head, true )
- ).
-
- rule( retract2( Head, Body ),
- and( notlocked( Head ),
- and( functor( Head, Name, Arity ),
- and( functor( Head2, Name, Arity ),
- and( =( ProcState, clause( 0 )),
- and( =( DState, rule( Head, nil )),
- and( =( NState, nstate( Count, IState )),
- and( getistate( IState ),
- and( getcount( Count ),
- and( decompilationOn( DState, NState ),
- and( call( Head2 ),
- and( decompilationOff( DState, NState ),
- and( nextClause( ProcState ),
- and( =( Head, Head2 ),
- and( fixClause( DState ),
- and( arg( 2, DState, Body ),
- and( arg( 1, ProcState, ClauseAddr ),
- nukeclause( ClauseAddr, Name, Arity ))
- )))))))))))))))).
-
- nextClause( _ ).
- rule( nextClause( ProcState ),
- and( getbp( Next ),
- and( mangle( 1, ProcState, Next ),
- fail
- ))).
-
- rule( getbp( BP ),
- and( $getbp,
- getterm( BP )
- )).
-
- % keysort/2
-
- rule(keysort(List,SortedList),
- and(length(List,Length), keysort(Length,List,_,SortedList) )).
-
- rule(keysort2(>,X1,X2,cons(X2,cons(X1,nil))), cut).
- keysort2(_,X1,X2,cons(X1,cons(X2,nil))).
-
- rule(keysort(2,cons(X1,L1),L,R),
- and(cut,
- and(comprises(L1,X2,L),
- and(compareKeys(Delta,X1,X2),keysort2(Delta,X1,X2,R))))).
-
- rule(keysort(1,cons(X,L),L,cons(X,nil)), cut).
- rule(keysort(0,L,L,nil),cut).
-
- rule(keysort(N,L1,L3,R),
- and(is(N1,idiv(N,2)),
- and(is(N2,sub(N,N1)),
- and(keysort(N1,L1,L2,R1),
- and(keysort(N2,L2,L3,R2), keymerge(R1,R2,R) ))))).
-
- rule(keymerge(nil,R,R), cut).
- rule(keymerge(R,nil,R), cut).
- rule(keymerge(R1,R2,cons(X,R)),
- and(comprises(R1,X1,R1a),
- and(comprises(R2,X2,R2a),
- and(compareKeys(Delta,X1,X2), keymerge(Delta,X,X1,X2,R1,R2,R1a,R2a,R) )))).
-
- rule(keymerge(>,X,_,X,R1,_,_,R2a,R),
- and(cut, keymerge(R1,R2a,R))).
-
- rule(keymerge(_,X,X,_,_,R2,R1a,_,R), keymerge(R1a,R2,R)).
-
- rule(compareKeys(Delta,pair(K1,X1),pair(K2,X2)),
- compare(Delta,K1,K2)).
-
-
- %
- %% setof( +Template, +Goal, -Solutions )
- %
- % All the instances of Template when Goal is provable are
- % collected into the list Solutions. Variables occuring in
- % Goal which do not also appear in Template and are not explicitly
- % quantified, will cause setof/3 to generate multiple Solutions upon
- % backtracking. Duplicate solutions are removed.
- %
-
-
- rule(setof(Template,Goal,Set),
- and(bagof(Template,Goal,RawSet), sort(RawSet,Set) )).
-
-
- %
- %% bagof( +Template, +Goal, -Solutions )
- %
- % All the instances of Template when Goal is provable are
- % collected into the list Solutions. Variables occuring in
- % Goal which do not also appear in Template and are not explicitly
- % quantified, will cause setof/3 to generate multiple Solutions upon
- % backtracking. Duplicate solutions are NOT removed.
- %
-
- rule(bagof(Template,Goal,Bag),
- and(excessVars(Goal,Template,NewGoal,ExcessVars),
- $bagof2(ExcessVars,Template,NewGoal,Bag) )).
-
- rule($bagof2(nil,Template,Goal,Bag),
- and(cut,
- and(findall(Template,Goal,Bag), different(Bag,nil) ))).
-
- rule($bagof2(ExcessVars,Template,Goal,Bag),
- and(findall(pair(ExcessVars,Template),Goal,RawBags),
- and(keysort(RawBags,GroupedBags), pick(GroupedBags,ExcessVars,Bag) ))).
-
- rule(pick(Bags,ExcessKey,OneBag),
- and(different(Bags,nil),
- and(select(Bags,Key1,Bag1,RestBags), decide(Key1,Bag1,RestBags,ExcessKey,OneBag) ))).
-
- rule(decide(Key,Bag,nil,Key,Bag), cut).
- decide(Key,Bag,Bags,Key,Bag).
- rule(decide(A1,A2,Bags,Key,Bag), pick(Bags,Key,Bag)).
-
- rule(excessVars(setof(NewTemplate,Goal,Set),Template,
- setof(NewTemplate,Goal,Set),Excess),
- and(cut,excessVars(and(Goal,Set),and(NewTemplate,Template),_,Excess) )).
-
- rule(excessVars(bagof(NewTemplate,Goal,Bag),Template,
- bagof(NewTemplate,Goal,Bag),Excess),
- and(cut,excessVars(and(Goal,Bag),and(NewTemplate,Template),_,Excess) )).
-
- rule(excessVars(@^(Var,Goal),Template,NewGoal,Excess),
- and(cut, excessVars(Goal,cons(Var,Template),NewGoal,Excess))).
-
- rule(excessVars(Goal,Template,Goal,Excess),
- and(getVars(Goal,nil,Vars),
- and(getVars(Template,nil,TemplateVars), filter(Vars,TemplateVars,nil,Excess)))).
-
- rule(select(cons(pair(Key,OutVars),RestBags),Key,
- cons(OutVars,RestOutVars),LeftOverBags),
- and(cut, select(RestBags,Key,RestOutVars,LeftOverBags) )).
-
- select(LeftOverBags,Key,nil,LeftOverBags).
-
-
- rule(getVars(Var,Vars,Vars),
- and(var(Var), alreadyIn(Term,Vars) )).
-
- rule(getVars(Var,Vars,cons(Var,Vars)),
- and(var(Var), cut)).
-
- rule(getVars(Atom,Vars,Vars),
- and(atomic(Atom), cut)).
-
- rule(getVars(Compound,VarsIn,VarsOut),
- and(univ(Compound,cons(_,Arguments)), getVars2(Arguments,VarsIn,VarsOut))).
-
-
- getVars2(nil,Vars,Vars).
- rule(getVars2(cons(Arg,Args),VarsIn,VarsOut),
- and(getVars(Arg,VarsIn,Vars1), getVars2(Args,Vars1,VarsOut) )).
-
- filter(nil,_,Filtered,Filtered).
-
- rule(filter(cons(Var,Vars),Filter,Inter,Filtered),
- and(alreadyIn(Var,Filter),
- and(cut, filter(Vars,Filter,Inter,Filtered) ))).
-
- rule(filter(cons(Var,Vars),Filter,Inter,Filtered),
- filter(Vars,Filter,cons(Var,Inter),Filtered) ).
-
- rule(alreadyIn(Term,cons(Term1,_)), ==(Term,Term1) ).
- rule(alreadyIn(Term,cons(_,Terms)), alreadyIn(Term,Terms) ).
-
-
- % buffer manipulation
-
- %
- %% newbuffer( -Buffer, +Size )
- %
-
- rule(newbuffer(Buffer,Size),
- and($newbuffer(Size), getterm(Buffer) )).
-
- %
- %% buffersize( +Buffer, -Size )
- %
-
- rule(buffersize(Buffer,Size),
- and($buffersize(Buffer), getterm(Size) )).
-
- %
- %% bufferpeek( +Buffer, +Offset, -Element )
- %
-
- rule(bufferpeek(Buffer,Offset,Element),
- and($bufferpeek(Buffer,Offset), getterm(Element) )).
-
- %
- %% bufferpoke( +Buffer, +Offset, +Element )
- %
-
- %
- %% statistics( -StatisticsVector )
- %
- % StatisticsVector is unified with a term of the following form:
- %
- % $stat( S, H, T, Ticks, C, P, L )
- %
- % where: S = size of local stack (bytes)
- % H = size of heap (bytes)
- % T = size of trail (bytes)
- % Ticks = Mac OS Ticks
- % C = clause space used (bytes)
- % P = size of procedure table
- % L = current logical inference count
- %
-
- rule( statistics( S ),
- and( $statistics,
- getterm( S )
- )).
-
-
- %
- % main/0 -- used to initiate the user interface
- %
-
- rule(main,
- and(getterm(Goal),
- and(call(Goal),
- and(success,
- cut
- )))).
- rule(main,failurehole).
-
- rule(failurehole,
- and( failure,
- failurehole
- )).
- rule(failurehole,
- failurehole
- ).
-
- rule( interactive,
- and( writel( 'Type halt. to get out' ),
- interactive2
- )).
-
- rule( interactive2,
- and( doQuery,
- fail
- )).
- rule( interactive2, interactive2 ).
-
- rule( doQuery,
- and( writel( 'Goal?' ),
- and( read( Q ),
- and( call( Q ),
- and( nl,
- and( writel( Q ),
- and( writel( 'More Answers?' ),
- and( read( YesNo ),
- and( moreAnswers( YesNo ),
- cut
- ))))))))).
- rule( doQuery,
- writel( 'No' )
- ).
-
- rule( moreAnswers( y ),
- and( cut,
- fail
- )).
- rule( moreAnswers( yes ),
- and( cut,
- fail
- )).
- moreAnswers( AnythingElse ).
-
- rule( consult,
- and( read( Clause ),
- addClause( Clause )
- )).
- rule( consult, consult ).
-
- addClause( end ).
- addClause( end_of_file ).
- rule( addClause( Clause ),
- and( assertz( Clause ),
- fail
- )).
-
- rule( ufault,
- and( =( X, f( a, Y, b )),
- and( =( Y, f( a, X, b )),
- =( X, Y )
- ))).
-
- rule( batch( Goal ),
- and( call( Goal ),
- and( nl,
- and( writel( 'Yes' ),
- halt
- )))).
- rule( batch( Goal ),
- and( nl,
- and( writel( 'No' ),
- halt
- ))).
-